package de.g18.it0a.jlaser.domain;

import java.awt.Shape;


abstract public class AbstractFixture implements Fixture {

    private final Position position;

    private Shape representation;


    protected AbstractFixture(Position aPosition) {
        position = aPosition;
    }

    @Override
    public Position getPosition() {
        return position;
    }

    @Override
    public Shape getRepresentation() {
        if (representation == null) {
            representation = buildRepresentation();
        }
        return representation;
    }

    abstract protected Shape buildRepresentation();

    @Override
    public boolean isSolid() {
        return false;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (position == null ? 0 : position.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object aOther) {
        if (aOther == this) {
            return true;
        }
        if (!(aOther instanceof Fixture)) {
            return false;
        }

        Fixture other = (Fixture) aOther;
        return getPosition().equals(other.getPosition());
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + "[position=" + getPosition()
        		                          + ",isSolid=" + isSolid() + "]";
    }
}
